package com.thinkgem.jeesite.modules.sys.service;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.modules.sys.dao.TbAdvertiseMapper;
import com.thinkgem.jeesite.modules.sys.entity.TbAdvertise;
import com.thinkgem.jeesite.modules.sys.entity.TbAdvertiseExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by lishuai on 2016/10/17.
 */
@Service
@Transactional(readOnly = true)
public class AdvertiseService  {
    @Autowired
    private TbAdvertiseMapper tbAdvertiseMapper;

    @Transactional(readOnly = false)
    public int saveOrUpdateAdvertise(TbAdvertise advertise) {
        int result=0;
        if(null!=advertise.getId() && !"".equals(advertise.getId())){
            result = tbAdvertiseMapper.updateByPrimaryKeySelective(advertise);
        }else{
            result = tbAdvertiseMapper.insertSelective(advertise);
        }
        return result;
    }

    public Page<TbAdvertise> findAdvertiseByPage(Page<TbAdvertise> tbAdvertisePage, TbAdvertise advertise) {
        advertise.setPage(tbAdvertisePage);
        List list = tbAdvertiseMapper.findByPage(advertise);
        tbAdvertisePage.setList(list);
        return tbAdvertisePage;
    }

    public TbAdvertise get(Integer id) {
        return tbAdvertiseMapper.selectByPrimaryKey(id);
    }
    @Transactional(readOnly = false)
    public void delete(TbAdvertise advertise) {
        tbAdvertiseMapper.deleteByPrimaryKey(advertise.getId());
    }
}
